home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / kh_gdi.zip / KH_GDI / PAINT.H < prev    next >
C/C++ Source or Header  |  1996-05-24  |  3KB  |  100 lines

  1. #ifndef __PAINT_H_
  2. #define __PAINT_H_
  3.  
  4. /*  Platform and drawing library (in theory) independent drawing tools.
  5.     Basic drawing primitives, rotation, mirror reflection, complex rotation,
  6.     zooming and scrolling.
  7. */
  8.  
  9. //#include <math.h>
  10. #include "general\geom.h"
  11. #include "kh_gdi\bgi_font.h"
  12. #include "kh_gdi\trigon.h"
  13.  
  14. #define R_STEP 50
  15. /*   Rotation could be simply processed if it is single operation. To use
  16.      nested rotations we use stack of rotations info structures. Example of
  17.      complex rotation:
  18.      void f1(int x, int y, int alpha) { ... perform rotation ... }
  19.      void f2(int x, int y, int alpha) { rotate(10,10,90); f1(x, y, alpha); }
  20.      Function f2() call rotation procedure and then call f1(), which call
  21.      another rotation. We could a) cancel first rotation and b) add first
  22.      and second rotations to complex transformation.
  23. */
  24.  
  25. struct RInfo
  26.     {
  27.     loc center;
  28.     int angle;
  29.     };
  30. ///////////////
  31. struct _export Stack
  32.     {
  33.     int used, total;
  34.     RInfo list[R_STEP];
  35.  
  36.     Stack();
  37.     ~Stack();
  38.     void push(RInfo* r);
  39.      void pop();
  40.      void flash();
  41.      };
  42.  
  43. ///////////////
  44. /*      Some additional facilities for any graphics library. Class
  45.      functions may be overloaded for adaptation to concrete graphic
  46.      interface (BGI, GDI, and so on).
  47.     Functions could set error code in kh_error_code variable.
  48.     The zoom and addzoom are deformation coeficients. You could
  49.      use zoom in any part of program. Addzoom is used only once to
  50.      set the additional deformation of the whole picture (for example
  51.      if context is changed from screen to printer), for preview and so on.
  52. */
  53.  
  54. class _export Paint : public BGI_Font, public Trigonometry
  55.      {
  56. //    protected:
  57.      public:
  58.     loc zoom;                     // Image deformation
  59.     loc add_zoom;                 // Additional deformation
  60.     loc lt;                       // Scroll of part of picture
  61.     loc add_scroll;               // Left - top clip of the whole picture
  62.     int fill;                     // Fill flag
  63.     int mirror;
  64.     public:
  65.     loc center;                   // Rotation center
  66.     int alpha;                    // Rotation angle
  67.     bool R_STACK;                 // Use or not stack of rotations
  68.     Stack* r_stack;               // Stack of rotations
  69.  
  70.     Paint();
  71.     ~Paint() { delete r_stack; }
  72.  
  73.     loc get_add_zoom() { return add_zoom; }
  74.     loc get_zoom() { return zoom; }
  75.  
  76.     void set_mirror(int m) { mirror = m; } // X coord. if no rotation
  77.     void set_stack(bool r) { R_STACK = r; r_stack->flash();
  78.         rotate(loc(0, 0), 0); }
  79.     void set_stack_soft(bool r) { R_STACK = r; }
  80.     void set_zoom(double x, double y) { zoom.X = x * add_zoom.X;
  81.         zoom.Y = y * add_zoom.Y; }    // No out-of-range control !!!
  82.     void set_add_zoom(double x, double y) { add_zoom.X = 100 * x;
  83.         add_zoom.Y = 100 * y; }
  84.     void set_scroll(int x, int y) { lt.X = x; lt.Y = y; }
  85.     void set_add_scroll(int x, int y) { add_scroll.X = x;
  86.         add_scroll.Y = y; }
  87.     void rotate(loc c, int a);
  88.     void rotate(int x, int y, int alpha) { rotate(loc(x, y), alpha); }
  89.     void set_fill(bool f) { fill = f; }
  90.  
  91. // Using alpha and center returns rotated coordinates
  92.     loc rot(int x, int y);
  93. // Return completely transformed point: rotated, zoomed and scrolled
  94.     loc transform(int x, int y);
  95.     };
  96.  
  97.  
  98. #endif __PAINT_H_
  99.  
  100.